/*
 * Copyright (c) 2015 FIRE Group Holding Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *
 * $Id: IndexController.java  2015年2月27日 下午11:08:51 jackLiang $
 */

package com.jkwzms.system.user.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jkwzms.system.resource.entity.tmp.Menu;
import com.jkwzms.system.resource.service.ResourceService;
import com.jkwzms.system.user.entity.User;
import com.jkwzms.system.user.web.bind.annotation.CurrentUser;

/**
 * Index Action
 * 
 * @author JackLiang(jacking124@gmail.com)
 * @date 2015年2月27日 下午11:08:51
 * @version v1.0.0
 */
@Controller
public class IndexController {

    @Autowired
    ResourceService resourceService;

    @RequestMapping(value = { "/{index:index;?.*}" })
    // spring3.2.2 bug see http://jinnianshilongnian.iteye.com/blog/1831408
    public String index(@CurrentUser User user, Model model) {

        // 这里的功能不完整

        return "index/index";
    }

    /**
     * 根据用户获取资源信息
     * 
     * @param user
     * @return
     */
    @RequestMapping(value = "loadMenu", method = RequestMethod.POST)
    @ResponseBody
    public List<Menu> loadMenu(@CurrentUser User user) {
        List<Menu> menus = this.resourceService.findMenus(user);
        return menus;
    }

    /**
     * 系统欢迎界面
     * 
     * @return
     */
    @RequestMapping(value = "welcome")
    public String welcome() {
        return "index/welcome";
    }

}
